package com.xbongbong.saas.script.modifyenum;

import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.NumericalLimitsPoJo;
import com.xbongbong.pro.enums.AmountFlagEnum;
import com.xbongbong.pro.enums.SummaryTypeEnum;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.ContractEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

/**
 * 资金管理一期改造，修改两个字段，新增三个字段
 * 新增字段：
 * 坏账金额:坏账金额的变化由回款单的变化而变化
 * 回款单
 * 核销预收款
 * <p>
 * 修改字段：
 * 关联信息-->关联回款
 * 新增应收款-->应收款
 *
 * @author chenshan
 * @version v1.0
 * @since 2019-11-25 14:54
 */
@Getter
public enum FundContractScriptEnum {
	//资金管理处理合同新增修改字段
	BAD_AMOUNT(ContractEnum.BAD_AMOUNT, 1),
//	ASSOCIATED_INFO(ContractEnum.ASSOCIATED_INFO, 1),
//	ADD_WRITE_OFF_PREPAYMENT(ContractEnum.ADD_WRITE_OFF_PREPAYMENT, 2),
//	ADD_PAYMENT_SHEET(ContractEnum.ADD_PAYMENT_SHEET, 2),
//	ADD_PAYMENT(ContractEnum.ADD_PAYMENT, 1),
	
//	BAD_AMOUNT(ContractEnum.BAD_AMOUNT, 1),
//	ASSOCIATED_INFO(ContractEnum.ASSOCIATED_INFO, 1),
//	ADD_WRITE_OFF_PREPAYMENT(ContractEnum.ADD_WRITE_OFF_PREPAYMENT, 1),
//	ADD_PAYMENT_SHEET(ContractEnum.ADD_PAYMENT_SHEET, 1),
//	ADD_PAYMENT(ContractEnum.ADD_PAYMENT, 1),
	;
	/**
	 * 合同
	 */
	private ContractEnum contractEnum;
	/**
	 * 类型，1:修改，2:新增
	 */
	private Integer type;
	
	FundContractScriptEnum(ContractEnum contractEnum, Integer type) {
		this.contractEnum = contractEnum;
		this.type = type;
	}
	
	public static List<FundContractScriptEnum> getAllEnum() {
		List<FundContractScriptEnum> list = new ArrayList<>();
		Collections.addAll(list, values());
		return list;
	}
	
	public static List<FundContractScriptEnum> getEnumByType(Integer type) {
		List<FundContractScriptEnum> list = new ArrayList<>();
		for ( FundContractScriptEnum cache : values() ) {
			if ( Objects.equals(type, cache.getType()) ) {
				list.add(cache);
			}
		}
		return list;
	}
	
	/**
	 * 初始化添加回款单
	 *
	 * @param fieldAttrEntity 字段
	 * @author chenshan
	 * @return void
	 * @date 2019-11-26 15:36
	 */
	public static void initAddPaymentSheet(FieldAttrEntity fieldAttrEntity) {
		fieldAttrEntity.setFieldId(UUID.randomUUID().toString());
		SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
		saasParticularAttributePoJo.setLinkBusinessType(XbbRefTypeEnum.PAYMENT_SHEET.getCode());
		fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
		fieldAttrEntity.setDefaultName("回款单");
		fieldAttrEntity.setAttrType(FieldTypeEnum.getFieldTypeEnum(ContractEnum.ADD_PAYMENT_SHEET.getFieldType()).getAlias());
		fieldAttrEntity.setNumericalLimitsFlag(1);
		fieldAttrEntity.setNumericalLimits(new NumericalLimitsPoJo(0D,50D));
		fieldAttrEntity.setIsOpen(1);
	}
	
	/**
	 * 初始化添加核销预收款
	 *
	 * @param fieldAttrEntity 字段
	 * @author chenshan
	 * @return void
	 * @date 2019-11-26 15:36
	 */
	public static void initAddWriteOffPrepayment(FieldAttrEntity fieldAttrEntity) {
		fieldAttrEntity.setFieldId(UUID.randomUUID().toString());
		SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
		saasParticularAttributePoJo.setLinkBusinessType(XbbRefTypeEnum.WRITE_OFF_PREPAYMENT.getCode());
		fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
		fieldAttrEntity.setDefaultName("核销回款单");
		fieldAttrEntity.setAttrType(FieldTypeEnum.getFieldTypeEnum(ContractEnum.ADD_WRITE_OFF_PREPAYMENT.getFieldType()).getAlias());
		fieldAttrEntity.setNumericalLimitsFlag(1);
		fieldAttrEntity.setNumericalLimits(new NumericalLimitsPoJo(0D,50D));
		fieldAttrEntity.setIsOpen(0);
	}
	
	/**
	 * 处理坏账金额
	 * @param fieldAttrEntity
	 * @author chenshan
	 * @return void
	 * @date 2019-11-26 15:36
	 */
	public static void initAddBadAmount(FieldAttrEntity fieldAttrEntity) {
		fieldAttrEntity.setFieldId(UUID.randomUUID().toString());
		fieldAttrEntity.setDefaultName("坏账金额");
		fieldAttrEntity.setNumericalLimits(new NumericalLimitsPoJo());
		fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.SUM.getType());
		fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
		fieldAttrEntity.setAttrType(FieldTypeEnum.getFieldTypeEnum(ContractEnum.BAD_AMOUNT.getFieldType()).getAlias());
	}
}
